Tables [dbo].[SupplementMain]
Properties
PropertyValue
Created10:31:40 AM Tuesday, March 02, 2010
Last Modified1:20:17 PM Thursday, February 23, 2012
Columns
NameData TypeMax Length (Bytes)Allow NullsDefault
Cluster Primary Key PK_SupplementMain: SupplementKeyForeign Keys FK_SupplementMain_UniformRegistry: [dbo].[UniformRegistry].SupplementKeySupplementKeyuniqueidentifier16
No
Namenvarchar(100)200
No
('')
Descriptionnvarchar(255)510
Yes
('')
DocumentVersionKeyuniqueidentifier16
Yes
Foreign Keys FK_SupplementMain_SupplementStatusRef: [dbo].[SupplementStatusRef].SupplementStatusCodeIndexes IX_SupplementMain_SupplementStatusCode: SupplementStatusCodeSupplementStatusCodeint4
No
((0))
Costdecimal(18,4)9
Yes
((0))
CostCollectionntextmax
Yes
UpdatedOndatetime8
No
(getdate())
Foreign Keys FK_SupplementMain_UserMain_UpdatedBy: [dbo].[UserMain].UpdatedByUserKeyIndexes IX_SupplementMain_UpdatedByUserKey: UpdatedByUserKeyUpdatedByUserKeyuniqueidentifier16
No
Foreign Keys FK_SupplementMain_UserMain_CreatedBy: [dbo].[UserMain].CreatedByUserKeyIndexes IX_SupplementMain_CreatedByUserKey: CreatedByUserKeyCreatedByUserKeyuniqueidentifier16
No
CreatedOndatetime8
No
Foreign Keys FK_SupplementMain_AccessMain: [dbo].[AccessMain].AccessKeyIndexes IX_SupplementMain_AccessKey: AccessKeyAccessKeyuniqueidentifier16
No
Foreign Keys FK_SupplementMain_SupplementTypeRef: [dbo].[SupplementTypeRef].SupplementTypeKeyIndexes IX_SupplementMain_SupplementTypeKey: SupplementTypeKeySupplementTypeKeyuniqueidentifier16
No
Foreign Keys FK_SupplementMain_SystemEntity: [dbo].[SystemEntity].SystemEntityKeyIndexes IX_SupplementMain_SystemEntityKey: SystemEntityKeySystemEntityKeyuniqueidentifier16
No
Foreign Keys FK_SupplementMain_GroupMain: [dbo].[GroupMain].NotificationGroupKeyIndexes IX_SupplementMain_NotificationGroupKey: NotificationGroupKeyNotificationGroupKeyuniqueidentifier16
Yes
MarkedForDeleteOndatetime8
Yes
Indexes Indexes
NameColumnsUnique
Cluster Primary Key PK_SupplementMain: SupplementKeyPK_SupplementMainSupplementKey
Yes
IX_SupplementMain_AccessKeyAccessKey
IX_SupplementMain_CreatedByUserKeyCreatedByUserKey
IX_SupplementMain_NotificationGroupKeyNotificationGroupKey
IX_SupplementMain_SupplementStatusCodeSupplementStatusCode
IX_SupplementMain_SupplementTypeKeySupplementTypeKey
IX_SupplementMain_SystemEntityKeySystemEntityKey
IX_SupplementMain_UpdatedByUserKeyUpdatedByUserKey
Triggers Triggers
NameANSI Nulls OnQuoted Identifier OnOn
asi_SupplementMain_Insert_Update
Yes
Yes
After Insert Update
Foreign Keys Foreign Keys
NameColumns
FK_SupplementMain_AccessMainAccessKey->[dbo].[AccessMain].[AccessKey]
FK_SupplementMain_GroupMainNotificationGroupKey->[dbo].[GroupMain].[GroupKey]
FK_SupplementMain_SupplementStatusRefSupplementStatusCode->[dbo].[SupplementStatusRef].[SupplementStatusCode]
FK_SupplementMain_SupplementTypeRefSupplementTypeKey->[dbo].[SupplementTypeRef].[SupplementTypeKey]
FK_SupplementMain_SystemEntitySystemEntityKey->[dbo].[SystemEntity].[SystemEntityKey]
FK_SupplementMain_UniformRegistrySupplementKey->[dbo].[UniformRegistry].[UniformKey]
FK_SupplementMain_UserMain_CreatedByCreatedByUserKey->[dbo].[UserMain].[UserKey]
FK_SupplementMain_UserMain_UpdatedByUpdatedByUserKey->[dbo].[UserMain].[UserKey]
SQL Script
CREATE TABLE [dbo].[SupplementMain]
(
[SupplementKey] [uniqueidentifier] NOT NULL,
[Name] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_SupplementMain_Name] DEFAULT (''),
[Description] [nvarchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL CONSTRAINT [DF_SupplementMain_Description] DEFAULT (''),
[DocumentVersionKey] [uniqueidentifier] NULL,
[SupplementStatusCode] [int] NOT NULL CONSTRAINT [DF_SupplementMain_SupplementStatusCode] DEFAULT ((0)),
[Cost] [decimal] (18, 4) NULL CONSTRAINT [DF_SupplementMain_Cost] DEFAULT ((0)),
[CostCollection] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[UpdatedOn] [datetime] NOT NULL CONSTRAINT [DF_SupplementMain_UpdatedOn] DEFAULT (getdate()),
[UpdatedByUserKey] [uniqueidentifier] NOT NULL,
[CreatedByUserKey] [uniqueidentifier] NOT NULL,
[CreatedOn] [datetime] NOT NULL,
[AccessKey] [uniqueidentifier] NOT NULL,
[SupplementTypeKey] [uniqueidentifier] NOT NULL,
[SystemEntityKey] [uniqueidentifier] NOT NULL,
[NotificationGroupKey] [uniqueidentifier] NULL,
[MarkedForDeleteOn] [datetime] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
CREATE TRIGGER [dbo].[asi_SupplementMain_Insert_Update]
    ON [dbo].[SupplementMain]
    FOR INSERT, UPDATE
AS
UPDATE    pm1
   SET    pm1.Cost = Coalesce(
        (SELECT    Sum(sm2.Cost)
           FROM    PackageMain pm2
                INNER JOIN PackageItem pi2 ON pm2.PackageKey = pi2.PackageKey
                INNER JOIN SupplementMain sm2 ON pi2.SupplementKey = sm2.SupplementKey
          WHERE    pm2.PackageKey = pm1.PackageKey), 0)
  FROM    PackageMain pm1
        INNER JOIN PackageItem pi1 ON pm1.PackageKey = pi1.PackageKey
        INNER JOIN inserted ON pi1.SupplementKey = inserted.SupplementKey

GO
ALTER TABLE [dbo].[SupplementMain] ADD CONSTRAINT [PK_SupplementMain] PRIMARY KEY CLUSTERED ([SupplementKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_SupplementMain_AccessKey] ON [dbo].[SupplementMain] ([AccessKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_SupplementMain_CreatedByUserKey] ON [dbo].[SupplementMain] ([CreatedByUserKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_SupplementMain_NotificationGroupKey] ON [dbo].[SupplementMain] ([NotificationGroupKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_SupplementMain_SupplementStatusCode] ON [dbo].[SupplementMain] ([SupplementStatusCode]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_SupplementMain_SupplementTypeKey] ON [dbo].[SupplementMain] ([SupplementTypeKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_SupplementMain_SystemEntityKey] ON [dbo].[SupplementMain] ([SystemEntityKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_SupplementMain_UpdatedByUserKey] ON [dbo].[SupplementMain] ([UpdatedByUserKey]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[SupplementMain] ADD CONSTRAINT [FK_SupplementMain_AccessMain] FOREIGN KEY ([AccessKey]) REFERENCES [dbo].[AccessMain] ([AccessKey])
GO
ALTER TABLE [dbo].[SupplementMain] ADD CONSTRAINT [FK_SupplementMain_GroupMain] FOREIGN KEY ([NotificationGroupKey]) REFERENCES [dbo].[GroupMain] ([GroupKey])
GO
ALTER TABLE [dbo].[SupplementMain] ADD CONSTRAINT [FK_SupplementMain_SupplementStatusRef] FOREIGN KEY ([SupplementStatusCode]) REFERENCES [dbo].[SupplementStatusRef] ([SupplementStatusCode])
GO
ALTER TABLE [dbo].[SupplementMain] ADD CONSTRAINT [FK_SupplementMain_SupplementTypeRef] FOREIGN KEY ([SupplementTypeKey]) REFERENCES [dbo].[SupplementTypeRef] ([SupplementTypeKey])
GO
ALTER TABLE [dbo].[SupplementMain] ADD CONSTRAINT [FK_SupplementMain_SystemEntity] FOREIGN KEY ([SystemEntityKey]) REFERENCES [dbo].[SystemEntity] ([SystemEntityKey])
GO
ALTER TABLE [dbo].[SupplementMain] ADD CONSTRAINT [FK_SupplementMain_UniformRegistry] FOREIGN KEY ([SupplementKey]) REFERENCES [dbo].[UniformRegistry] ([UniformKey])
GO
ALTER TABLE [dbo].[SupplementMain] ADD CONSTRAINT [FK_SupplementMain_UserMain_CreatedBy] FOREIGN KEY ([CreatedByUserKey]) REFERENCES [dbo].[UserMain] ([UserKey])
GO
ALTER TABLE [dbo].[SupplementMain] ADD CONSTRAINT [FK_SupplementMain_UserMain_UpdatedBy] FOREIGN KEY ([UpdatedByUserKey]) REFERENCES [dbo].[UserMain] ([UserKey])
GO
Uses
Used By